<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>标签管理</title>
    <script type="text/javascript">

    </script>
</head>
<body>
<script type="text/javascript">
    var userInfoDataGrid;
    $(function() {
        userInfoDataGrid = $('#userInfoDataGrid').datagrid({
            url : '${path }/userInfo/dataGrid.do',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                width : '40',
                title : 'id',
                field : 'id',
                sortable : true
            },  {
                width : '120',
                title : '用户名',
                field : 'username'
            }, {
                width : '100',
                title : '手机',
                field : 'phone'
            } , {
                width : '150',
                title : '邮箱',
                field : 'email'
            }, {
                width : '120',
                title : '昵称',
                field : 'nickname'
            }, {
                width : '100',
                title : '姓名',
                field : 'trueName'
            },{
                width : '90',
                title : '生日',
                field : 'birthday',
                formatter:function (value, row, index) {
                    return formatDateboxYMD(value,"yyyy-MM-dd")
                }
            },  {
                width : '70',
                title : '省',
                field : 'province'
            }, {
                width : '70',
                title : '市',
                field : 'city'
            }, {
                width : '100',
                title : '区',
                field : 'area'
            },  {
                width : '50',
                title : '性别',
                field : 'sex',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 0:
                            return '男';
                        case 1:
                            return '女';
                    }
                }
            }, {
                width : '50',
                title : '年龄',
                field : 'age'
            }, {
                width : '80',
                title : '余额',
                field : 'money'
            }, {
                width : '50',
                title : '类型',
                field : 'type',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 0:
                            return '用户';
                        case 1:
                            return '商家';
                        case 2:
                            return '员工';
                        case 3:
                            return '专家';
                        case 4:
                            return '企业';
                    }
                }
            }, {
                width : '50',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '停用';
                    case 1:
                        return '启用';
                    }
                }
            }, {
                field : 'action',
                title : '操作',
                width : 300,
                formatter : function(value, row, index) {
                    var str = '';
                        <shiro:hasPermission name="/userInfo/edit.do">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="userInfo-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editUserInfoFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/userInfo/recharge.do">
                        str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                        str += $.formatString('<a href="javascript:void(0)" class="userInfo-easyui-linkbutton-recharge" data-options="plain:true,iconCls:\'fi-pencil icon-red\'" onclick="rechargeFun(\'{0}\');" >余额</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/userInfo/resetPwd.do">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="userInfo-easyui-linkbutton-resetPwd" data-options="plain:true,iconCls:\'fi-pencil icon-red\'" onclick="resetPwdFun(\'{0}\');" >重置密码</a>', row.id);
                        </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.userInfo-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.userInfo-easyui-linkbutton-recharge').linkbutton({text:'余额'});
                $('.userInfo-easyui-linkbutton-resetPwd').linkbutton({text:'重置密码'});
            },
            toolbar : '#userInfoToolbar'
        });
    });



    function addUserInfoFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 300,
            href : '${path }/userInfo/addPage.do',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = userInfoDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#userInfoAddForm');
                    f.submit();
                }
            } ]
        });
    }
    function editUserInfoFun(id) {
        if (id == undefined) {
            var rows = userInfoDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            userInfoDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 1000,
            height : 450,
            href : '${path }/userInfo/editPage.do?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    console.log("funIn1");
                    parent.$.modalDialog.openner_dataGrid = userInfoDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    console.log("funIn2");
                    var f = parent.$.modalDialog.handler.find('#userInfoEditForm');
                    console.log("funIn3");
                    f.submit();
                    console.log("funIn4");
                }
            } ]
        });
    }

    function resetPwdFun(id) {

        parent.$.messager.confirm('询问', '您确定要重置用户密码吗？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/userInfo/resetPwd.do', {
                    userId : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        userInfoDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }

    function rechargeFun(id){
        parent.$.modalDialog({
            title : '余额',
            width : 500,
            height : 200,
            href : '${path }/userInfo/rechargePage.do?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = userInfoDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#rechargeForm');
                    f.submit();
                }
            } ]
        });
    }

    //查询标签
    function dolabelDetailSearch(){
        var queryParams = {};
            queryParams.statusSearchWord =$("#statusSearchWord").combobox('getValue');
            queryParams.typeSearchWord =$("#typeSearchWord").combobox('getValue');
            queryParams.usernameSearchWord = $("#usernameSearchWord").val();
            queryParams.phoneSearchWord =$("#phoneSearchWord").val();
            queryParams.emailSearchWord =$("#emailSearchWord").val();
        var options = $("#userInfoDataGrid").datagrid('getPager').data("pagination").options;
        options.pageNumber = 1;
        //重新加载
        $("#userInfoDataGrid").datagrid('options').url = "${path }/userInfo/dataGrid.do";
        $("#userInfoDataGrid").datagrid('options').queryParams = queryParams;
        $("#userInfoDataGrid").datagrid('reload');
    }
    function resetSearch() {
        $("#usernameSearchWord").val("");
        $("#phoneSearchWord").val("");
        $("#emailSearchWord").val("");
        $("#statusSearchWord").combobox("setValue","");
        $("#typeSearchWord").combobox("setValue","");
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="userInfoDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="userInfoToolbar" style="display: none;">

    <shiro:hasPermission name="/userInfo/add.do">
        <a onclick="addUserInfoFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
        &nbsp;&nbsp;&nbsp;&nbsp;
    </shiro:hasPermission>

    状态:<select id="statusSearchWord" name="statusSearchWord" class="easyui-combobox" data-options="width:60,editable:false,panelHeight:'auto'">
            <option value="">全部</option>
            <option value="1">启用</option>
            <option value="0">停用</option>
        </select>
    类型:<select id="typeSearchWord" name="typeSearchWord" class="easyui-combobox" data-options="width:60,editable:false,panelHeight:'auto'">
            <option value="">全部</option>
            <option value="0">用户</option>
            <option value="1">商家</option>
            <option value="2">员工</option>
            <option value="3">专家</option>
            <option value="4">企业</option>
        </select>

    用户名:<input type="text" id="usernameSearchWord" name="usernameSearchWord"/>

    手机:<input type="text" id="phoneSearchWord" name="phoneSearchWord"/>

    邮箱:<input type="text" id="emailSearchWord" name="emailSearchWord"/>


    <input type="button" class="easyui-linkbutton " value="重置" onclick="resetSearch();"/>
    &nbsp;
    <input type="button" class="easyui-linkbutton" value="搜索" onclick="dolabelDetailSearch();"/>

</div>
</body>
</html>